


/*function SeekAll()
{
  var argsArray=new Array();
  argsArray.push(newArg("Action","Seek"));
  sendRequest("../controller/controllerCity.jsp",argsArray,show);
}
*/



function clear_fields(){
    document.getElementById("modelvehicles").value="";
    document.getElementById("carpalte").value="";
    document.getElementById("capacity").value="";
    document.getElementById("iddrivpri").value="";
    document.getElementById("iddrivre").value="";
    document.getElementById("typevehicles").value="";
}

function addvehicles()
{
    var argsArray=new Array();
    argsArray.push(newArg("Action","Add"));
     var txtModel=document.getElementById("modelvehicles").value;
    argsArray.push(newArg("MODEL",txtModel));
    var txtPlate=document.getElementById("carpalte").value;
    argsArray.push(newArg("PLATE",txtPlate));
    var txtCapacity=document.getElementById("capacity").value;
    argsArray.push(newArg("CAPACITY",txtCapacity));
    var txtnameconprin=document.getElementById("iddrivpri").value;
    argsArray.push(newArg("NAMEPRIN",txtnameconprin));
    var txtnameconre=document.getElementById("iddrivre").value;
    argsArray.push(newArg("NAMERE",txtnameconre));
    var txttypeve=document.getElementById("typevehicles").value;
    argsArray.push(newArg("TYPE",txttypeve));
   // var argsStr=argsArray.join("&");
   // alert(argsStr);
    //jConfirm('hola','Error', 'Error Dialog');
    if(txtModel != "" && txtPlate != "" && txtCapacity != "" && txtnameconprin != "" && txtnameconre != "" && txttypeve != ""){

       sendRequest("../controller/controllerVehicles_1.jsp",argsArray,btnAdd_onclick_response);
}
else{
    jConfirm('Faltan datos por llenar o incorrectos','Error', 'Error Dialog');
}
}

function btnAdd_onclick_response()
{
  if (isValidResponse(this))
  {
    var res=this.responseText;
    if(res!="")
    {
       //alert(res)
      var info=eval("("+res+")");
      if(info.errorcode == 0){
        jAlert('Regitrado Correctamente','Ok', 'Success Dialog');
        clear_fields();
      }
      else{
         jConfirm('Error guardando datos','Error', 'Error Dialog');
      }
}

  }

}

function updatevehicles()
{
    var argsArray=new Array();
    argsArray.push(newArg("Action","Update"));
       var txtModel=document.getElementById("modelvehicles").value;
    argsArray.push(newArg("MODEL",txtModel));
    var txtPlate=document.getElementById("carpalte").value;
    argsArray.push(newArg("PLATE",txtPlate));
    var txtCapacity=document.getElementById("capacity").value;
    argsArray.push(newArg("CAPACITY",txtCapacity));
    var txtnameconprin=document.getElementById("iddrivpri").value;
    argsArray.push(newArg("NAMEPRIN",txtnameconprin));
    var txtnameconre=document.getElementById("iddrivre").value;
    argsArray.push(newArg("NAMERE",txtnameconre));
    var txttypeve=document.getElementById("typevehicles").value;
    argsArray.push(newArg("TYPE",txttypeve));
    //var argsStr=argsArray.join("&");
    //alert(argsStr);
    if(txtModel!= ""  && txtPlate!= "" && txtCapacity!= "" && txtnameconprin!= "" && txtnameconre!= "" && txttypeve!= ""){
    sendRequest("../controller/controllerVehicles_1.jsp",argsArray,btnUpdate_onclick_response);
}
else{
    jConfirm('Faltan datos por llenar o incorrectos','Error', 'Error Dialog');
}
}

function btnUpdate_onclick_response()
{
  if (isValidResponse(this))
  {
    var res=this.responseText;
    if(res!="")
    {
      var info=eval("("+res+")");
      if(info.errorcode == 0){
       jAlert('Se a Modificado Correctamente','Ok', 'Success Dialog');
       clear_fields();
  }
      else{
          jConfirm('Error Modificando los Datos','Error', 'Error Dialog');
      }
}

  }

}

function deletevehicles()
{
    var argsArray=new Array();
    argsArray.push(newArg("Action","Delete"));
   var plate=document.getElementById("carpalte").value;
    argsArray.push(newArg("PLATE",plate));
   
   //var argsStr=argsArray.join("&");
    //alert(argsStr);
   if(plate != ""){
   sendRequest("../controller/controllerVehicles_1.jsp", argsArray,btnDelete_onclick_response);
}
else{
    jConfirm('Debe Ingresar el ID Del vehiculo','Error', 'Error Dialog');
}

}

function btnDelete_onclick_response()
{
    if (isValidResponse(this))
  {
    var res=this.responseText;
    if(res!="")
    {
      var info=eval("("+res+")");
      if(info.errorcode == 0){
       jAlert('Se a Eliminado Correctamente','Ok', 'Success Dialog');
       clear_fields();
     //document.getElementById("txtID").value="";
  }
      else{
        jConfirm('Error al Eliminar','Error', 'Error Dialog');
      }
}
  }
}

function show()
{
    if (isValidResponse(this))
    {

        var res=this.responseText;
        alert(res);
     if(res!="")
    {
        alert(res);
        var info=eval("("+res+")");
        alert(info);
    }
    
    else
     jConfirm('No Found','Error', 'Error Dialog');
    }
}

/*
function idvehicles(){
    var argsArray=new Array();
    argsArray.push(newArg("Action","Vehicle"));
    sendRequest("../controller/controllerVehicles.jsp",argsArray,showidvehicles);
}


function showidvehicles(){
    if (isValidResponse(this))
    {
        var res=this.responseText;

        if(res!="")
        {
            var info=eval("("+res+")");
            if(info.errorcode == 0)
            {
                alert(res)
                if(info.data.length<1){
                    jConfirm('No hay id disponibleslllllllll', 'Error', 'Error Dialog');
                }else{
                    var selF = document.getElementById("idvehicles");
                    var selectF = "";
                    for(var i=0; i<info.data.length; i++){
                        selectF+='<option>';
                        selectF+=info.data[i].i+'</option>';
                    }
                    selF.innerHTML = selectF;
                }

            }else
                jConfirm('No Found','Error', 'Error Dialog');
        }
    }

}
*/

function dripri(){
    var argsArray=new Array();
    argsArray.push(newArg("Action","Drive1"));
    sendRequest("../controller/controllerVehicles_1.jsp",argsArray,showdripri);
}


function showdripri(){
    if (isValidResponse(this))
    {
        var res=this.responseText;
        if(res!="")
        {
           // alert(res)
            var info=eval("("+res+")");
            if(info.errorcode == 0)
            {
                if(info.data.length<1){
                    jConfirm('No existen Conductores  disponibles', 'Error', 'Error Dialog');
                }else{
                    var selF = document.getElementById("iddrivpri");
                    var selectF = "";
                    for(var i=0; i<info.data.length; i++){
                        selectF+='<option>';
                        selectF+=info.data[i].i+'</option>';
                    }
                    selF.innerHTML = selectF;
                }

            }else
                jConfirm('No Found','Error', 'Error Dialog');
        }
    }

}

function drire(){
    var argsArray=new Array();
    argsArray.push(newArg("Action","Drivee"));
    sendRequest("../controller/controllerVehicles_1.jsp",argsArray,showdrire);
}


function showdrire(){
    if (isValidResponse(this))
    {
        var res=this.responseText;
        if(res!="")
        {
            var info=eval("("+res+")");
            if(info.errorcode == 0)
            {
                if(info.data.length<1){
                    jConfirm('No existen Conductores  disponibles', 'Error', 'Error Dialog');
                }else{
                    var selF = document.getElementById("iddrivre");
                    var selectF = "";
                    for(var i=0; i<info.data.length; i++){
                        selectF+='<option>';
                        selectF+=info.data[i].d+'</option>';
                    }
                    selF.innerHTML = selectF;
                }

            }else
                jConfirm('No Found','Error', 'Error Dialog');
        }
    }

}

function loadInformation(){
    dripri();
    drire();
    //idvehicles();
}
